home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
network
/
ka9q
/
nhclb120.zoo
/
ax_mbx.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-18
|
48KB
|
1,924 lines
/* Ok, I admit it... what I've done here is a mortal sin, but the XOBBS module
for ax_mbx.c is so different from the W9NK mailbox, and I hate forcing folks
to move files around before running a make, so here it is... the two cat'ed
together with an "if XOBBS ... else ... endif" wrapper... sick, but it
works... Bdale */
static domboxdisplay();
static void free_mbx();
static mbx_line();
static mbx_msg();
static mbx_to();
static mbx_data();
static void mbx_disc();
void fwdxmit();
void fwdrecv();
void fwdstate();
void axbbs_xmit();
char xogetc();
#ifdef XOBBS
/* XOBBS.C module to link NET thru IPC message queues to the XOBBS mailbox. */
/* Jim Durham, W2XO, 1-5-89 */
/* requires a call to axchk() to be inserted in the main commutator loop of
the net main.c code */
#include <stdio.h>
#include "global.h"
#include "config.h"
#include "mbuf.h"
#include "ax25.h"
#include "timer.h"
#include "lapb.h"
#include "cmdparse.h"
#include "iface.h"
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include "netrom.h"
#include "nr4.h"
#include "ax_mbx.h"
#ifdef UNIX
#undef toupper
#undef tolower
#include <memory.h>
#include <string.h>
#endif
#ifdef BSD
char *sprintf();
#endif
/*#define DEBUG 1*/
static char conbuf[10][10]; /*buffers used in getcon() and fwdcon()*/
int conindex,conchar;
int fwdflag; /*flag to do various forwarding tasks*/
int pid;
int fwdbbsstate = NOCON; /* con/discon state of forwarding bbs process */
int smsgqid; /* send message queue (from viewpoint of bbs) */
int rmsgqid; /* receive message queue (from viewpoint of bbs) */
int scmsgqid; /* send CONTROL message queue */
int rcmsgqid; /* receive CONTROL message queue */
int lastindex; /*last bbs index used*/
int nsend;
int ax25mbox;
char temp[128];
char *bbsexe = "xobbs"; /*path to bbs executable*/
struct ax25_cb *bbscb; /*forwarding bbs control block*/
struct message msg;
struct mboxsess * base = NULLMBS; /*pointer to base of mailbox chain*/
struct mboxsess fwdstruct; /*forwarding session*/
#ifdef SID2
extern struct ax25_addr bbscall;
#endif
static struct mboxsess *
newmbox()
{
struct mboxsess * mbp ;
if(base == NULLMBS){
base =(struct mboxsess *)malloc(sizeof(struct mboxsess));
base->next = NULLMBS;
initmbox(base);
return base;
}
else{
mbp = base;
while(mbp->next != NULLMBS) /*go up the chain to the top*/
mbp = mbp->next;
mbp->next =(struct mboxsess *)malloc(sizeof(struct mboxsess));
mbp->next->next = NULLMBS;
initmbox(mbp->next);
return mbp->next;
}
}
initmbox(mbp)
struct mboxsess * mbp;
{
mbp->bytes = 0;
mbp->gotbytes = 0;
mbp->mtxtptr = mbp->rmsgbuf.mtext;
}
freembox(mbp)
struct mboxsess * mbp;
{
struct mboxsess *p;
if(mbp == base){ /*special case for base session*/
if(base->next != NULLMBS)/*if base is NOT the only session*/
base = base->next; /*then make base point to next session*/
else
base = NULLMBS; /*otherwise,just set base to NULLMBS*/
free(mbp); /*free up the storage*/
return; /*and go away*/
}
p = base;
for(;;){
if(p->next == mbp){ /*if the next upward session is THE one*/
p->next = mbp->next; /*eliminate the next upward session*/
free(mbp);
return;
}
if(p->next == NULLMBS){ /*something is wrong here!*/
free(mbp); /*try to fix it*/
return;
}
p = p->next;
}
}
axchk() /* service any ax25 connections w2xo 9-1-88*/
{
int rdcnt;
struct mbuf *bp;
struct mboxsess * mbp;
char *cp;
int testsize,size;
void axinit();
/* initialization code removed. call to axinit() direct from main now. */
if(base == NULLMBS) /*no mailboxes?..then leave*/
goto fcontchk;
mbp = base; /*point to the session base*/
while(mbp != NULLMBS){ /*and climb the session links*/
if(mbp->gotbytes < 1) /*if we need input*/
if((mbp->gotbytes=msgrcv(smsgqid,&mbp->rmsgbuf,1024,(long)mbp->pid,
IPC_NOWAIT|0600)) < 1) /*and there is none, ..punt*/
goto contchk;
else /*got input!*/
mbp->mtxtptr = mbp->rmsgbuf.mtext; /*new message buffer, set to start*/
testsize = min(mbp->bytes,mbp->cbadr.axbbscb->paclen+1); /* get the minimum of the # */
size = min(testsize, mbp->gotbytes) + 1; /* of bytes avail and paclen*/
bp = alloc_mbuf((int16)size); /* then min of avail and have*/
cp = bp->data;
if(mbp->proto == AX25){
*cp++ = PID_FIRST | PID_LAST | PID_NO_L3;
bp->cnt =1;
}
else bp->cnt = 0;
while(bp->cnt < size && mbp->gotbytes){
*cp++ = *mbp->mtxtptr++;
bp->cnt++;
mbp->gotbytes--;
}
if(mbp->proto == AX25)
send_ax25(mbp->cbadr.axbbscb,bp);
else
send_nr4(mbp->cbadr.axnrcb,bp);
/*now, check for control messages*/
contchk: rdcnt=msgrcv(scmsgqid,&msg,1024,(long)mbp->pid,IPC_NOWAIT|0600);
#ifdef DEBUG
if(rdcnt > 0) printf("net:Control Message received: rdcnt=%d\n",rdcnt);
#endif
switch(rdcnt){
case 0: break;
case -1: /*perror("axchk002");*/
break;
default: if(msg.mtext[0] == 'K'){
#ifdef DEBUG
printf("recbbs: K received\n");
#endif
kill(mbp->pid,9);
wait(NULLCHAR);
clearque(mbp->pid);
if(mbp->proto == AX25)
disc_ax25(mbp->cbadr.axbbscb);
else
disc_nr4(mbp->cbadr.axnrcb);
freembox(mbp);
}/* if K */
}/* switch */
mbp = mbp->next;
}/*while loop*/
fcontchk: chkfwd(); /*check the forwarder*/
}
dombox(argc, argv)
int argc ;
char *argv[] ;
{
if (argc < 2) {
domboxdisplay() ;
return 0 ;
}
if (argv[1][0] == 'y' || (strcmp(argv[1],"on") == 0))
ax25mbox = 1 ;
else if (argv[1][0] == 'n' || (strcmp(argv[1],"off") == 0))
ax25mbox = 0 ;
else if (argv[1][0] == '?')
printf("ax25 mailbox is %s\n", ax25mbox ? "on" : "off") ;
else
printf("usage: mbox [y|n|?]\n") ;
return 0 ;
}
static domboxdisplay()
{
struct mboxsess * mbp;
printf("Process-ID &cb Protocol User\n") ;
mbp = base;
while(mbp != NULLMBS){
printf("%-13d%-13x",mbp->pid,mbp->cbadr.axbbscb);
if(mbp->proto == AX25)
printf("Ax25 %s\n",mbp->call);
else
printf("Net/Rom %s\n",mbp->call);
mbp = mbp->next;
}/*while loop*/
printf("\n\n");
printf("Forwarder State is: ");
switch(fwdflag){
case 0: printf("NOFWD\n");
break;
case 1: printf("SPAWNBBS\n");
break;
case 2: printf("DOCONNECT\n");
break;
case 3: printf("READXMIT\n");
break;
case 4: printf("GETCON\n");
break;
case 5: printf("CLEARCON\n");
break;
case 6: printf("WAITING\n");
break;
default: printf("UNDEFINED\n");
break;
}
}
/* Incoming mailbox session via ax.25 */
/* * This is the ax25 receive upcall function
*it gathers incoming data and stuff it down the IPC queue to the proper BBS
*/
void
mbx_incom(axp,cnt)
struct ax25_cb *axp;
int16 cnt;
{
#ifndef SID2
char arg1[10],arg2[10],arg3[10],arg4[10],arg5[10];
void mbx_tx(), mbx_rx(), mbx_state();
int j;
struct mboxsess *mbp;
struct mbuf *bp;
struct mbuf *recv_ax25();
mbp =newmbox(); /*after this, this is a mailbox connection*/
/* so, make a new mailbox session*/
axp->r_upcall = mbx_rx ;
axp->t_upcall = mbx_tx ;
axp->s_upcall = mbx_state;
mbp->cbadr.axbbscb=axp;